import time

# 未优化的代码
def unoptimized_search(data, target):
    start_time = time.time()
    for item in data:
        if item == target:
            for subItem in data:
                if subItem == target:
                    pass
    end_time = time.time()
    print(f"Unoptimized search took {end_time - start_time:.6f} seconds")

# 优化后的代码
def optimized_search(data, target):
    start_time = time.time()
    set_data = set(data)  # 将列表转换为集合
    if target in set_data:  # 使用集合进行查找
        if target in set_data:
            pass
    end_time = time.time()
    print(f"Optimized search took {end_time - start_time:.6f} seconds")

if __name__ == "__main__":
    data = list(range(1000000))
    target = 999999
    unoptimized_search(data, target)
    optimized_search(data, target)